package com.study.system.course.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {

    public static final String QUEUE_UPDATE = "course-update-queue";
    public static final String QUEUE_DELETE = "course-delete-queue";
    public static final String EXCHANGE_COURSE = "course-exchange";
    public static final String KEY_UPDATE = "course-update-key";
    public static final String KEY_DELETE = "course-delete-key";

    @Bean
    public Queue queueUpdate(){
        return new Queue(QUEUE_UPDATE);
    }

    @Bean
    public Queue queueDelete(){
        return new Queue(QUEUE_DELETE);
    }

    @Bean
    public TopicExchange courseExchange(){
        return new TopicExchange(EXCHANGE_COURSE);
    }

    @Bean
    public Binding bindingQueueUpdate(){
        return BindingBuilder.bind(queueUpdate()).to(courseExchange()).with(KEY_UPDATE);
    }

    @Bean
    public Binding bindingQueueDelete(){
        return BindingBuilder.bind(queueDelete()).to(courseExchange()).with(KEY_DELETE);
    }
}
